﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NEXEntidad;
using System.Globalization;

public partial class CargaEventos : System.Web.UI.Page
{
    #region Eventos de Pagina
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (User.Identity.IsAuthenticated && ((Usuario)Session["Usuario"]).EsAdministrador)
            {

                if (Request.QueryString["idEvento"] != null)
                {
                    EventoCultural evento = new EventoCultural(Convert.ToInt32(Request.QueryString["idEvento"]));
                    evento.LlamarAObtener();

                    this.txtCodigo.Text = evento.Id.ToString();
                    this.txtTitulo.Text = evento.Titulo;
                    this.txtDescripcion.Text = evento.Descripcion;
                    this.txtDetalle.Text = evento.Detalle;
                    this.txtFechaDesde.Text = evento.FechaDesde.ToString("dd/MM/yyyy");
                    this.txtFechaHasta.Text = evento.FechaHasta.ToString("dd/MM/yyyy");
                    this.hidEsInsert.Value = "1";
                }
            }
            else
            {
                Response.Redirect("Default2.aspx");
            }
        }

    }
    protected void btnAceptar_Click(object sender, EventArgs e)
    {
        EventoCultural evento = new EventoCultural(this.txtCodigo.Text == "" ? 0 : Convert.ToInt32(this.txtCodigo.Text));
        evento.Descripcion = this.txtDescripcion.Text;
        evento.Detalle = this.txtDetalle.Text;
        evento.FechaDesde = DateTime.ParseExact(this.txtFechaDesde.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
        evento.FechaHasta = DateTime.ParseExact(this.txtFechaHasta.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
        evento.Titulo = this.txtTitulo.Text;
        evento.Activo = true;
        evento.EsInsert = this.hidEsInsert.Value == "1" ? false : true;

        evento.Salvar();

        this.LimpiarPantalla();

    }

    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        Response.Redirect("ListarEventos.aspx");
    }

    #endregion

    #region Metodos Privados
    private void LimpiarPantalla()
    {
        try
        {
            this.txtDescripcion.Text = "";
            this.txtDetalle.Text = "";
            this.txtFechaHasta.Text = "";
            this.txtFechaDesde.Text = "";
            this.txtTitulo.Text = "";
            this.txtCodigo.Text = "";
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #endregion


}
